﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace OutlookInvitationTest1
{
    public class OutlookMeetingGenerator
    {
        public String buildMeetingRequest(DateTime start, DateTime end, int attendeeID,string attendeeName, string attendeeEmail, string organizerUserName, string subject, string description, string location)
        {
            System.Text.StringBuilder sw = new System.Text.StringBuilder();
            //TODO UID musi byc unikalny! bo inaczej outlook nie będzie rozpoznawał róznych wiadomości!
            //string UID = "040000008200E00074C5B7101A82E00800000000A050E7D9F218CD01000000000000000010000000E19D655B9619A445B65A74D56F30B46A";
            //uid 
            string UID = Guid.NewGuid().ToString();

            sw.AppendLine("BEGIN:VCALENDAR");
            sw.AppendLine("VERSION:2.0");
            sw.AppendLine("METHOD:REQUEST");
            sw.AppendLine("BEGIN:VEVENT");
            sw.AppendLine("ATTENDEE;CN=\"" + attendeeName + "(" + attendeeEmail + ")\";RSVP=TRUE:mailto:" + attendeeEmail);
            sw.AppendLine("CLASS:PUBLIC");
            sw.AppendLine(string.Format("CREATED:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow));
            sw.AppendLine("DESCRIPTION:" + description);
            sw.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", end));
            sw.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow));
            sw.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", start));
            sw.AppendLine("ORGANIZER;CN=\"NAME\":mailto:" + organizerUserName);
            sw.AppendLine("SEQUENCE:0");
            sw.AppendLine("UID:" + UID);
            sw.AppendLine("LOCATION:" + location);
            sw.AppendLine("SUMMARY;LANGUAGE=en-us:" + subject);
            sw.AppendLine("BEGIN:VALARM");
            sw.AppendLine("TRIGGER:-PT720M");
            sw.AppendLine("ACTION:DISPLAY");
            sw.AppendLine("DESCRIPTION:Reminder");
            sw.AppendLine("END:VALARM");
            sw.AppendLine("END:VEVENT");
            sw.AppendLine("END:VCALENDAR");

            return sw.ToString();
        }

        
    }

   
}